<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>健康膳食系统</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        :root {
            --primary: #4CAF50;
            --primary-light: #81C784;
            --primary-lighter: #C8E6C9;
            --secondary: #8BC34A;
            --dark: #2E7D32;
            --light: #F1F8E9;
            --text: #333;
            --text-light: #666;
            --error: #f44336;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Noto Sans SC', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f1f8e9 0%, #c8e6c9 50%, #81c784 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            animation: gradientBG 15s ease infinite;
            background-size: 200% 200%;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .container {
            width: 100%;
            max-width: 800px;
            background: rgba(255, 255, 255, 0.85);
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            border: 1px solid rgba(129, 199, 132, 0.3);
        }

        .header {
            background: linear-gradient(to right, var(--primary), var(--primary-light));
            color: white;
            padding: 25px;
            text-align: center;
            font-size: 1.8rem;
            font-weight: 500;
            letter-spacing: 1px;
        }

        .form-container {
            display: flex;
            transition: transform 0.5s ease;
        }

        .form-page {
            min-width: 100%;
            padding: 30px;
        }

        .form-group {
            margin-bottom: 20px;
            position: relative;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: var(--text);
            font-weight: 500;
            font-size: 15px;
        }

        input, select {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s;
            background: rgba(255, 255, 255, 0.9);
        }

        input:focus, select:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
            outline: none;
        }

        .btn {
            background: linear-gradient(to right, var(--primary), var(--primary-light));
            color: white;
            border: none;
            padding: 14px 20px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            width: 100%;
            transition: all 0.3s;
            margin-top: 10px;
            letter-spacing: 1px;
        }

        .btn:hover {
            background: linear-gradient(to right, var(--dark), var(--primary));
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(76, 175, 80, 0.2);
        }

        .btn-secondary {
            background: transparent;
            color: var(--primary);
            border: 1px solid var(--primary-light);
        }

        .btn-secondary:hover {
            background: rgba(129, 199, 132, 0.1);
            border-color: var(--primary);
        }

        .toggle-form {
            text-align: center;
            margin-top: 20px;
            color: var(--text-light);
        }

        .toggle-btn {
            color: var(--primary);
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
            padding: 2px 5px;
            border-radius: 4px;
        }

        .toggle-btn:hover {
            background: rgba(129, 199, 132, 0.2);
            text-decoration: underline;
        }

        .gender-options {
            display: flex;
            gap: 15px;
            margin-top: 10px;
        }

        .gender-option {
            flex: 1;
            position: relative;
        }

        .gender-option input {
            position: absolute;
            opacity: 0;
        }

        .gender-option label {
            display: block;
            padding: 12px;
            background: rgba(241, 248, 233, 0.8);
            border-radius: 8px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
            border: 1px solid #e0e0e0;
        }

        .gender-option input:checked + label {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .progress-bar {
            height: 4px;
            background: var(--primary-lighter);
            margin-bottom: 20px;
        }

        .progress {
            height: 100%;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            width: 50%;
            transition: width 0.5s;
            border-radius: 0 2px 2px 0;
        }

        h2 {
            color: var(--text);
            position: relative;
            padding-bottom: 10px;
            margin-bottom: 25px;
        }

        h2::after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 50px;
            height: 3px;
            background: var(--primary);
            border-radius: 3px;
        }

        .error-message {
            color: var(--error);
            margin: 10px 0;
            text-align: center;
            font-size: 14px;
            animation: fadeIn 0.3s;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @media (max-width: 600px) {
            .container {
                border-radius: 10px;
            }

            .header {
                padding: 20px;
                font-size: 1.5rem;
            }

            .form-page {
                padding: 20px 15px;
            }

            body {
                padding: 10px;
                animation: none;
                background: var(--primary-lighter);
            }
        }
    </style>
</head>
<body>
<div id="app">
    <div class="container">
        <div class="header">
            健康膳食系统
        </div>
        <div class="progress-bar">
            <div class="progress" :style="{width: isLogin ? '50%' : '100%'}"></div>
        </div>

        <!-- 错误消息显示 -->
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>

        <div class="form-container" :style="{transform: isLogin ? 'translateX(0)' : 'translateX(-100%)'}">
            <!-- 登录表单 -->
            <div class="form-page">
                <h2 style="text-align: center;">用户登录</h2>
                <form action="user/login" method="post">
                    <div class="form-group">
                        <label for="login-username">账号</label>
                        <input
                                id="login-username"
                                type="text"
                                name="username"
                                placeholder="请输入账号"
                                required>
                    </div>
                    <div class="form-group">
                        <label for="login-password">密码</label>
                        <input
                                id="login-password"
                                type="password"
                                name="password"
                                placeholder="请输入密码"
                                required>
                    </div>
                    <button type="submit" class="btn">登 录</button>
                </form>
                <div class="toggle-form">
                    还没有账号？<span class="toggle-btn" @click="toggleForm">立即注册</span>
                </div>
            </div>

            <!-- 注册表单 -->
            <div class="form-page">
                <h2 style="text-align: center;">用户注册</h2>
                <form action="user/register" method="post">
                    <div class="form-group">
                        <label for="reg-username">账号</label>
                        <input
                                id="reg-username"
                                type="text"
                                name="username"
                                placeholder="请输入账号"
                                required>
                    </div>
                    <div class="form-group">
                        <label for="reg-password">密码</label>
                        <input
                                id="reg-password"
                                type="password"
                                name="password"
                                placeholder="请输入密码"
                                required>
                    </div>
                    <div class="form-group">
                        <label for="confirm-password">确认密码</label>
                        <input
                                id="confirm-password"
                                type="password"
                                name="confirmPassword"
                                placeholder="请再次输入密码"
                                required>
                    </div>
                    <div class="form-group">
                        <label>性别</label>
                        <div class="gender-options">
                            <div class="gender-option">
                                <input
                                        type="radio"
                                        id="male"
                                        name="gender"
                                        value="male"
                                        required>
                                <label for="male">男</label>
                            </div>
                            <div class="gender-option">
                                <input
                                        type="radio"
                                        id="female"
                                        name="gender"
                                        value="female">
                                <label for="female">女</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="reg-height">身高(cm)</label>
                        <input
                                id="reg-height"
                                type="number"
                                name="height"
                                placeholder="例如：170"
                                required>
                    </div>
                    <div class="form-group">
                        <label for="reg-weight">体重(kg)</label>
                        <input
                                id="reg-weight"
                                type="number"
                                name="weight"
                                step="0.1"
                                placeholder="例如：65.5"
                                required>
                    </div>
                    <div class="form-group">
                        <label for="reg-age">年龄</label>
                        <input
                                id="reg-age"
                                type="number"
                                name="age"
                                placeholder="例如：25"
                                required>
                    </div>
                    <button type="submit" class="btn" >注 册</button>
                    <button type="button" class="btn btn-secondary" @click="toggleForm">返回登录</button>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            isLogin: true
        },
        methods: {
            toggleForm() {
                this.isLogin = !this.isLogin;
            }
        }
    });
</script>
</body>
</html>